<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>物料管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/basic/materials";
		var basic_Url1="${ctx}/basic/matertype";
		var basic_WUrl="basic/matertype";
		var basic_Title="物料";
		var show_Width=320;
		var show_Hight=150;
		var pid = null;
		var flag = true;
		var grid;
		function createSearch(){
			init(1,8,'80,100,80,100,80,100,80,100','20%');

			//第一行的数据
			addCommon(0,0,"lable","名称：");
			addCommon(0,1,"txtlike","zd002Name");
			addCommon(0,2,"lable","编码：");
			addCommon(0,3,"txtlike","zd001Code");
			addCommon(0,4,"lable","型号：");
			addCommon(0,5,"txtlike","zd004Model");
			addCommon(0,6,"lable","规格：");
			addCommon(0,7,"txtlike","zd026Size");
		}
		
		function searchAP(){
			multipleSearch("#table1",true,"",basic_Url+"/list.do");
		}
		
		
		function gettreeData() 
		 {    
			var manager = null;
			manager = $("#tree1").ligerGetTreeManager(); 
			manager.clear();
	        manager.loadData(null, basic_Url1+'/tree.do');
	        manager.collapseAll();
		 }
		
		jQuery(document).ready(function() {
			//创建JQGRID表格
			 grid = $("#table1").ligerGrid({
		        columns: [
		                   { display: '条码', name: 'id', width: 60 },
			                  { display: '物料编码', name: 'zd001Code', width: 110 },
			                  { display: '物料名称', name: 'zd002Name', width: 110 },
			                  { display: '物料类型', name: 'zd029MaterTypeId', width: 110,render: function (item)
			                	 {
		                		 	if(item.basicMaterialsTypeDO==null){
		                			 	return "";
		                		 	}else{
		                			 	return item.basicMaterialsTypeDO.zd002Name;
		                		 	}
		                		 } 
			                  },
			                  { display: '型号', name: 'zd004Model', width: 200 },
			                  { display: '尺寸', name: 'zd026Size', width: 150 },
			                  { display: '基本单位', name: 'zd007Unit', width: 60, render: function (item){
			                		 if(item.basicStapleUnitDO==null){
			                			 return "";
			                		 }else{
			                			 return item.basicStapleUnitDO.zd002Name;
			                		 }
			                  	}
			                  },
			                  { display: '助记码', name: 'bizMnemonic', width: 60 },
			                  { display: '零售价', name: 'zd010RetailPrice', width: 60 },
			                  { display: '进货价', name: 'zd009Price', width: 60 },
			                  { display: '最大库存', name: 'zd012HighestInventory', width: 60 },
			                  { display: '最小库存', name: 'zd011MinmunInventory', width: 60 },
			                  { display: '创建时间', name: 'bizCreatorDate', width: 100,
			                	  render: function (item){
			                		  var cdate=new Date(item.bizCreatorDate);
			                		  return formatDate(cdate,"yyyy-MM-dd");
			                	  }
			                  },
		                  	  { display: '功能说明', name: 'zd006Description', width: 140 }
		                     ],usePager: true,
		                      pageSize:15,
		                      pageSizeOptions :[15,25,35],
		                      enabledSort:false,
		                      url : basic_Url+"/list.do",
		                      width: "98%", height:"95%", checkbox: true,      
		                      onDblClickRow : function (data, rowindex, rowobj){
		                    	  edititem(data);
		                       },
		                      toolbar: { items: [
												  { text: '增加材料', click: additem, icon: 'add' },
												  { line: true },
		                                          { text: '修改', click: getSelected, icon: 'modify' },
		                                          { line: true },
		                                          { text: '删除', click: delematerial, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' },
		                                          { line: true },
		                                          { text: '导出', click: exportExcel, img: '${ctx}/images/excel.gif' }
		                                          ]
		                                          }
		                  });
			$("#pageloading").hide();
			
			
			$("#layout1").ligerLayout({ leftWidth: 200,height: '100%',heightDiff:-24,space:4});
			var actionNodeID=null;
			$("#tree1").ligerTree({  
				 url: basic_Url1+'/tree.do',
				 nodeWidth: 115,
				 checkbox: false,
		         slide: false,
		         onClick:function(node){
		        	 actionNodeID = node.data.id;
	        		 multipleSearch("#table1",true,"",basic_Url+"/list.do?ID="+node.data.id);
		         }
		     });
			
			 var menu;
			 menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
		         [
		         { text: '增加材料', click: additem, icon: 'add' }
		         ]
		         }); 
			
			 var menu1;
			 menu1 = $.ligerMenu({ top: 100, left: 100, width: 120, items:
		         [
		         { text: '增加材料', click: additem, icon: 'add' }
		         ]
		         });
			 
			 //添加物料
			 function additem(){
				 if(actionNodeID == null || actionNodeID.length<=0){
					 $.dialog.alert("请选择需要添加的类型!");
					 return false;
				 }
					var url = "basic/materials/operate/add/"+actionNodeID+".do";
					ShowIframeDialog("operate","添加物料",url,320,300);
			 }
			 
			//修改物料
			 function edititem(data){
					var url = "basic/materials/operate/edit/"+data.id+".do";
					ShowIframeDialog("operate","修改物料",url,320,300);
			 }
			
			//导出物料
			function exportExcel(){
			   	var filtersStr = generateCondition();
			   	if(actionNodeID==null){
			   		$.dialog.confirm("您没有选择物料类型！是否导出符合条件的材料！",function(){
						var path = basic_Url+"/exportExcel.do?filters="+filtersStr+"&_search=true";
					   	window.open(path,"_blank");
			   		});
			   	}
			   	if(actionNodeID!=null){
			   		$.dialog.confirm("是否导出当前选择类型的物料！如果需导出全部物料请刷新当前页！",function(){
			   			var path = basic_Url+"/exportExcel.do?filters="+filtersStr+"&_search=true&ID="+actionNodeID;
					   	window.open(path,"_blank");
			   		});
			   	}
			}
			/* 
			function exportExcel(){
				var filtersStr = generateCondition();
			   	window.open(basic_Url+"/exportExcel.do?filters="+filtersStr+"&_search=true","_blank");
			} */
				
			//修改物料
			 function getSelected(){
				 /* if(flag){
					 $.dialog.alert("请选择三级以下的类型!");
					 return false;
				 } */
				 var grid = $("#table1").ligerGetGridManager(); 
					var rows = grid.getCheckedRows();
					var data =grid.getSelectedRow();
					if(rows.length==0){
						$.dialog.alert("请选择一行数据!");
						return false;
					}else{
						edititem(data);
					}
			}
			 
		});
		
		function delematerial(){
			 var manager = $("#table1").ligerGetGridManager(); 
				var rows =manager.getSelectedRows();
				var bol = false;
				if (rows==null || 0 == rows.length){
						$.dialog.alert('请选择需要操作删除的行！');
						return;
				}
				for(var i=0;i<rows.length;i++){
				 	if (rows[i].bizCreatorName != '${user.name}'){
				 		bol = true;
					}
				}
				if(bol){
					$.dialog.alert('请选择自己创建的草稿单据进行删除操作!');
					return;
				}else{
					del();
				}
		 }
		document.onkeydown=keyListener;   
		function keyListener(e){   
		    e = e ? e : event;  
		    if(e.keyCode == 13){   
		    	searchAP();
		    }   
		}  
	</script>
	
  </head>
 <body style="padding:10px" onload="createSearch()">  
       <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
                    <div class="subBar">
			             <ul>
				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="searchAP()">查询</button></div></div></li>
				             <li><a class="button" onclick="clearSearch()"><span>重置</span></a></li>
			             </ul>
	                </div>
               </div>
          </div>
       <div id="layout1">
            <div position="left" title="物料分类信息">
            <div style="width:100%; height:380px; float:left;overflow:auto;  ">
   				 <ul id="tree1"></ul>
    		</div> 
            </div>
            <div position="center" title="物料列表" id="table1">
            
            </div>   
      </div>  
    </body>
</html>